You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Conditionally compute visual line layout in Thinking component
Summary
• In cli/src/components/thinking.tsx, conditionally compute visual line wrapping and markdown content formatting based on thinkingCollapseState.
• Previously, getLastNVisualLines (which measures tokens and performs visual word wrapping across the entire reasoning text) was invoked unconditionally on every render, even when thinkingCollapseState === 'hidden' (where neither preview nor expanded text is displayed) or 'expanded' (where preview lines are never displayed).
• Measured via @opentui/react and @opentui/core/testing end-to-end across 100 actual React render cycles (5,000-char reasoning text):
Hidden state: 753.35 ms down to 148.99 ms (5.05x faster end-to-end React render).
Expanded state: 779.28 ms down to 181.15 ms (4.30x faster end-to-end React render).
Isolated visual wrapping: 616.26 ms down to 0.00 ms.
• In cli/src/components/blocks/thinking-block.tsx, added a fast-path for blocks.length === 1 when extracting combinedContent to avoid allocating intermediate .map() arrays on every streaming token update.
• Added unit tests in cli/src/components/__tests__/thinking.test.tsx verifying component rendering across all three states (preview, hidden, and expanded).
Test plan
[✓] bun test --config=/dev/null src/components/__tests__/thinking.test.tsx — 3 pass, 0 fail
[✓] bun run --cwd cli typecheck — passed with 0 errors
[✓] PR hygiene check passed
Nice, focused change. The core insight—that getLastNVisualLines and the expanded-content normalization were being computed unconditionally even when hidden (neither is shown) or expanded (preview isn't shown)—is legitimate and the fix in thinking.tsx preserves the original render output for all three states (I traced showPreview/showFull through the new branches and they match the old semantics: hidden computes neither, expanded skips the preview-line wrap, preview skips the expanded-markdown normalization).
The thinking-block.tsx fast-path for blocks.length === 1 is a reasonable micro-optimization to avoid a throwaway array from .map() on every streaming token, though its actual impact is probably marginal compared to the wrapping fix — that's fine, it's still correct and harmless.
Good to see unit tests added for all three collapse states (preview, hidden, expanded) verifying the rendered frame contents rather than just internal state, which is the right level to test a terminal UI component at.
A couple of things worth double checking before this lands: (1) confirm getLastNVisualLines and expandedContent truly have no side effects relied on elsewhere (e.g. some parent measuring width off lines) — a quick grep of call sites would settle this. (2) The benchmark numbers in the PR description are useful context but aren't part of the diff/test suite, so they're not verifiable in review — that's fine for a description but the correctness argument stands independently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Conditionally compute visual line layout in Thinking component
Summary
• In
cli/src/components/thinking.tsx, conditionally compute visual line wrapping and markdown content formatting based onthinkingCollapseState.• Previously,
getLastNVisualLines(which measures tokens and performs visual word wrapping across the entire reasoning text) was invoked unconditionally on every render, even whenthinkingCollapseState === 'hidden'(where neither preview nor expanded text is displayed) or'expanded'(where preview lines are never displayed).• Measured via
@opentui/reactand@opentui/core/testingend-to-end across 100 actual React render cycles (5,000-char reasoning text):• In
cli/src/components/blocks/thinking-block.tsx, added a fast-path forblocks.length === 1when extractingcombinedContentto avoid allocating intermediate.map()arrays on every streaming token update.• Added unit tests in
cli/src/components/__tests__/thinking.test.tsxverifying component rendering across all three states (preview,hidden, andexpanded).Test plan
[✓]
bun test --config=/dev/null src/components/__tests__/thinking.test.tsx— 3 pass, 0 fail[✓]
bun run --cwd cli typecheck— passed with 0 errors[✓] PR hygiene check passed